<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Repos\ShopRepo;
use App\Repos\ShopUserRepo;

class ShopUserController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $shops = ShopRepo::get();
        $where['shop_id'] = $request->shop_id;
        $list = ShopUserRepo::getList($where);
        $roles = ['100'=>'老板','1'=>'店员'];
        return view('admin.shop_user.index',compact('list','where','roles','shops'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $rs['status'] = false;
        $data = $request->except(['_token']);
        $data['token'] = str_random(16);
        $flag = ShopUserRepo::create($data);
        if($flag) {
            $rs['status'] = true;
            $rs['msg'] = '操作成功';
        }
        return back()->with('rs',$rs);


    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $rs['status'] = false;
        $flag = ShopUserRepo::del($id);
        if($flag) {
            $rs['status'] = true;
            $rs['msg'] = '删除成功';
        }
        return back()->with('rs',$rs);
    }
}
